require(['jquery','token','sweetalert'], function($,token,swal) {
	var content = new Vue({
		el: '#content',
		methods: {
			submit: function(){
				var name=$('#username').val();
				var password=$('#password').val();
				if(!name){
					swal("Oops...", "用户名不能为空", "error");
				}else if(!password){
					swal("Oops...", "密码不能为空", "error")
				}else{
					$.ajax({
						url:'/login',
						method:'post',
						data:{
							name:name,
							password:password
						},
						success:function(data){
							var redirectUrl=decodeURIComponent(window.location.search.substr(1).split('=')[1]||'/');
							if(data.token){
								token.start(data.token);
								window.location.href=redirectUrl;
							}else{
								swal("Oops...", data.err, "error")
							}
						}
					})
				}
			}
		}
	})
});